package org.system.core.config;

import org.springframework.stereotype.Component;
import org.system.core.utils.ServletUtils;

import javax.servlet.http.HttpServletRequest;

@Component
public class ServerConfig {

    public String getUrl() {
        HttpServletRequest request = ServletUtils.getRequest();
        return getDomain(request);
    }

    public static String getDomain(HttpServletRequest request) {
        StringBuffer url = request.getRequestURL();
        String contextPath = request.getServletContext().getContextPath();
        return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString();
    }

}
